package cn.kgc.cloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 课工场
 * @date 2024/1/5
 * @description
 */
@RestController
@RequestMapping("hystrix")
public class HystrixController {

    @GetMapping
    @HystrixCommand(fallbackMethod = "method1FallBack")
    public String method1(Integer id){

        System.out.println("--------method1-------------");

        if (id<0){
            throw  new RuntimeException("参数异常");
        }

        return "hystrix service ok";
    }


    //快速响应方法的参数列表要和抛出异常的方法保持一致   有异常出现时调用快速响应方法会将参数传入
    public String method1FallBack(Integer id){

        System.out.println("-----------method1FallBack-------------");
        return "参数异常 id = "+id;
    }

}
